package com.itcoon.cloud.framework.temporal;/**
 * @author Athric Yu
 * 2024/11/15
 **/

import com.itcoon.cloud.framework.properties.TemporalPatternConfigProperties;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

/**
 *
 *
 * @author Athric Yu
 * 2024/11/15
 **/
public class LongZonedDateTimeConverter extends AbstractConverter<Long, ZonedDateTime> {

    public LongZonedDateTimeConverter(TemporalPatternConfigProperties.TemporalSerialization<Long, ZonedDateTime> temporalSerialization) {
        super(temporalSerialization);
    }



    @Override
    public ZonedDateTime parse(Long source) {
        return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source), ZoneOffset.of(temporalSerialization.getZoneId()));
    }

    @Override
    public Long format(ZonedDateTime temporal) {
        return temporal.toInstant().toEpochMilli();
    }
}
